import { User, $User, UserId } from './model';
import { createUserRepository } from './repository.user';

const userRepository = createUserRepository();

export async function findByUserId(userId: UserId): Promise<$User> {
  return await userRepository.selectByUserId(userId);
}

export async function findByUsername(username: string): Promise<$User> {
  return await userRepository.selectByUsername(username);
}

export async function newUser(username: string): Promise<User> {
  return await userRepository.insertUser({ id: -1, username, nickName: username });
}
